// MQTT参数
var PageMqttParam = {
    id: "PageMqttParam", //页面id
    menu: "i18n.lan.menu.dataTrans", //所属菜单(一级菜单名)
    title: "i18n.lan.menu.PageMqttParam", //标题（二级菜单名）
    icon: "icon-me-gprs", //图标
    refreshBtnCmd: "DUMP_CORE", //刷新按钮指令
    saveBtn: true, //保存按钮
    el: [ //控件
        {
            elname:"style",
            text:'#PageMqttParam > label{min-width:150px;}',
        },
        {
            elname: "checkbox",
            label: i18n.lan.PageMqttParam.sessionType,
            id:"mqttParam_session",
            endRow: true,
            attrs: {
                dumpKey: "MQTT_SESSION",
                cmdKey: "MQTTSESSION",
            }
        },
        {
            elname: "checkbox",
            label: i18n.lan.PageMqttParam.retain,
            id:"mqttParam_reatin",
            endRow: true,
            attrs: {
                dumpKey: "MQTT_RETAIN",
                cmdKey: "MQTTRETAIN",
            }
        },     
        {
            elname: "text",
            label: i18n.lan.PageMqttParam.publishTo,
            endRow: true,
            attrs: {
                dumpKey: "MQTT_PTO",
                cmdKey: "MQTTPUBLISHTO",
            }
        },
        {
            elname: "text",
            label: i18n.lan.PageMqttParam.keepAlive,
            endRow: true,
            attrs: {
                dumpKey: "MQTT_KEEP",
                cmdKey: "MQTTKEEPALIVE",
            }
        },     
        {
            elname: "text",
            label: i18n.lan.PageMqttParam.publishTopic,
            endRow: true,
            attrs: {
                dumpKey: "MQTTPUBTOPIC",
                cmdKey: "MQTTPUBTOPIC",
            }
        },    
        {
            elname: "text",
            label: i18n.lan.PageMqttParam.subscribeTopic,
            endRow: true,
            attrs: {
                dumpKey: "MQTTSUBTOPIC",
                cmdKey: "MQTTSUBTOPIC",
            }
        }, 
        {
            elname: "combobox",
            label:i18n.lan.PageMqttParam.qos,
            id:"mqttParam_qos",
            items:"i18n.lan.PageMqttParam.qosItems",
            endRow: true,
            attrs: {
                dumpKey: "MQTT_QOS",
                cmdKey: "MQTTQOS",
            }
        },  
        {
            elname: "datagrid",
            rowCount: Device.getNodesCount("gprs"), //必选,行数
            data: {
                width:990,
                columns: [
                    [{
                            //序号
                            field: "index",
                            width: 40,
                            align: "center",
                        },
                        {//服务器地址
                            field: "serverAddress",
                            editor: Easyui.editor.textbox,
                            dumpKey: "IOTSVR<n>",
                            dumpParamIndex: 0,
                            cmdKey: "IOTSVR<n>,", //注意逗号
                            otherFields: "serverPort,transType,transProtocol", //其它的参数的field
                            width: 200,
                        },
                        {//端口号
                            field: "serverPort",
                            editor: Easyui.editor.numberbox,
                            dumpKey: "IOTSVR<n>",
                            dumpParamIndex: 1,
                            width: 80,
                        },
                        {//tcp/udp类型
                            field: "transType",
                            formatter: Easyui.formatter.combobox,
                            editor: new Easyui.editor.Combobox(Device.getTransTypeItemsKV()),
                            dumpKey: "IOTSVR<n>",
                            dumpParamIndex: 2,
                            width: 120,
                        },
                        {//传输数据协议
                            field: "transProtocol",
                            formatter: Easyui.formatter.combobox,
                            editor: new Easyui.editor.Combobox(Device.getTransProtocolItemsKV()),
                            dumpKey: "IOTSVR<n>",
                            dumpParamIndex: 3,
                            width: 140,
                        },
                        {//用户名
                            field: "username",
                            editor: Easyui.editor.textbox,
                            dumpKey: "MQTT<n>SET",
                            dumpParamIndex: 1,
                            cmdKey: "MQTTSVRSET=<n>,", //注意逗号
                            getValue:"mqttParam_getMqttParam(rows[row].index)",//不能使用row作行号
                            width: 120,
                        },
                        {//密码
                            field: "password",
                            editor: Easyui.editor.textbox,
                            dumpKey: "MQTT<n>SET",
                            dumpParamIndex: 2,
                            width: 150,
                        },
                        {//client id
                            field: "clientId",
                            editor: Easyui.editor.textbox,
                            dumpKey: "MQTT<n>SET",
                            dumpParamIndex: 0,
                            width: 120,
                        },
                    ]
                ],
            },
        },   
        {
            elname:"label",
            text:i18n.lan.PageMqttParam.shareGprsSverver,
        }
    ],
}
CmdPage.add(PageMqttParam); //添加到页面管理

//获得参数：用户名,密码,版本,clientId,dataType
function mqttParam_getMqttParam(row) {
    let username = PageMqttParam.dgData.rows[row].username;
    let password = PageMqttParam.dgData.rows[row].password;
    let version = "4";//默认使用MQTTv4
    let clientId = PageMqttParam.dgData.rows[row].clientId;
    let dataType = PageMqttParam.dgData.rows[row].dataType;
    let protocolVersion = PageMqttParam.dgData.rows[row].protocolVersion;
    return username + "," + password + "," + version + "," + clientId+","+dataType+","+protocolVersion;
}